<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="oneroom.admin.code.codeModel" %>
<jsp:useBean id="code" scope="page" class="oneroom.admin.code.codeDao" />
<%
	String	hdrcode = request.getParameter("hdrcode") == null ? "" : request.getParameter("hdrcode");
	int     giCount       	= 0;			//리스트 for문 break문에 사용
	int     giRecordcnt   	= 0;			//리스트의 카운터에 사용
	int     giPageSize    	= 10;  			// 한페이지에 나타내고자 하는 List수
	int     giCurPage     	= 1;   			// 현재 Page
	int     giCurBlock    	= 0;   			// 현재 Block
	int     giTotPage     	= 0;   			// 총 Page수
	//쿼리를 돌려서 가지고 오는 값
	List list = code.getAdmDtlList(hdrcode);
	if (list.size() > 0 ) {
		//전체 게시물 수
		giRecordcnt = code.getAdmDtlCount(hdrcode); 			// 총 list 수
	}
	if (giRecordcnt > 0) {  // 조건에 맞는 값이 있으면....
		giTotPage  = giRecordcnt / giPageSize;
		if (giRecordcnt % giPageSize != 0) {
			giTotPage = giTotPage + 1;			// 총 Page수를 구한다...
		}
	}	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>원룸 - 코드 관리</title>
<script type="text/javascript" src="/admin/js/default.js"></script>
<link href="/admin/css/ifr_default.css" rel="stylesheet" type="text/css" />
<!--[if lte IE 6]><link rel="stylesheet" href="/admin/css/forie6.css" type="text/css" /><![endif]-->
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
	$('#wrtBtn').click(function() {
		window.location.href="write.jsp";
	});
});

	function addComCodeRow() {
		document.getElementById("pattern_comcode_row").style.display = "";		
	}
	function hideComCode() {
		document.getElementById("pattern_comcode_row").style.display = "none";
	}
	function regComCode() {
		var frm = document.frm;
		if(frm.uescheck.checked == true){
			frm.useyn.value = "Y";
		}else{
			frm.useyn.value = "N";
		}
		frm.gubun.value = "DI";
		frm.submit();
	}	
	function editComCode(cnt) {
		fillForm(cnt);
		var frm = document.frm;
		frm.gubun.value = "DU";
		frm.submit();
	}
	function deleteComCode(cnt) {
		if (confirm("삭제하시겠습니까?")) {
			fillForm(cnt);
			var frm = document.frm;
			frm.gubun.value = "DD";
			frm.submit();
		}
	}	
	function fillForm(cnt) {
		var code = document.getElementById("code"+cnt).value;
		var codename = document.getElementById("codename"+cnt).value;
		var comment = document.getElementById("comment"+cnt).value;
		var useyn = document.getElementById("useyn"+cnt).checked == true ? "Y" : "N";
		var frm = document.frm;
		frm.code.value = code;
		frm.codename.value = codename;
		frm.comment.value = comment;
		frm.useyn.value = useyn;
	}	

//-->
</script>
</head>
<body>
<div class="content">
	<form name="frm" method="post" action="dbx.jsp">
	<input type="hidden" name="gubun" value="">	
	<input type="hidden" name="useyn" value="">	
	<input type="hidden" name="hdrcode" value="<%=hdrcode %>">	
	<table class="list-normal" cellpadding="0" cellspacing="0" summary="게시판 관리" >
	<caption>코드 관리 </caption>
	<col width="5%" />
	<col width="10%" />
	<col width="15%" />
	<col width="15%" />
	<col width="20%" />
	<col width="10%" />
	<col width="20%" />
	<tbody>
        <tr id="pattern_comcode_row" style="display: none;" style="border:0px" >
		  	<td>&nbsp;</td>
            <td><%=hdrcode %></td>
            <td><input type="text" id="code" name="code" value="" size="5%" maxlength="6"/></td>
            <td><input type="text" id="codename" name="codename" value="" size="10%" /></td>
            <td><input type="text" id="comment" name="comment" value="" size="10%" /></td>
            <td><input type="checkbox" id="uescheck" name="uescheck" checked /></td>
            <td><input type="button" class="btn_ch3" id="saveButton" value="저장" onclick="regComCode();" />
            	<input type="button" class="btn_ch3" id="cancelButton" value="취소" onclick="hideComCode();"/>
			</td>
        </tr>	
	<%
		if(list != null && list.size() > 0){
			giCount  = 1;
			giRecordcnt = giRecordcnt - ( giCurPage -1 ) * giPageSize;	
			for(int i = 0; i<list.size(); i++){
				codeModel model = (codeModel)list.get(i);
	%>	
	<tr>
		<td width="5%"><%=giRecordcnt %></td>
		<td width="10%"><input type="text" id="hdrcode<%=giCount %>" value="<%=model.getHdrcode() %>" size="5%" maxlength="6" disabled="disabled"></td>
		<td width="15%"><input type="text" id="code<%=giCount %>" value="<%=model.getCode() %>" size="5%" maxlength="6"></td>
		<td width="15%"><input type="text" id="codename<%=giCount %>" value="<%=model.getCodename() %>" size="10%" /></td>
		<td width="20%"><input type="text" id="comment<%=giCount %>" value="<%=model.getComment() %>" size="10%" /></td>
		<td width="10%"><input type="checkbox" id="useyn<%=giCount %>" <%if(model.getUseyn().equals("Y")){%>checked<%} %> /></td>
		<td width="20%"><input type="button" class="btn_ch3" id="editButton" value="수정" onclick="editComCode('<%=giCount %>');" />
        	<input type="button" class="btn_ch3" id="deleteButton" value="삭제" onclick="deleteComCode('<%=giCount %>');"/>
        </td>
	</tr>
	<%
			giCount = giCount + 1;	
			giRecordcnt = giRecordcnt - 1;
			}
		}else{
	%>	
	<tr><td colspan="8">등록된 내용이 없습니다.</td></tr>
	<%
		}
	%>	
	</tbody>
	</table>
	</form>		
</div>
</body>
</html>